package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.PtSysVideoVo;
import com.ruoyi.system.domain.bo.PtSysVideoBo;
import com.ruoyi.system.service.IPtSysVideoService;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiOperation;

/**
 * 视频Controller
 *
 * @author ruoyi
 * @date 2022-03-26
 */
@Validated
@Api(value = "视频控制器", tags = {"视频管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/video")
public class PtSysVideoController extends BaseController {

    private final IPtSysVideoService iPtSysVideoService;

    /**
     * 查询视频列表
     */
    @ApiOperation("查询视频列表")
    @PreAuthorize("@ss.hasPermi('system:video:list')")
    @GetMapping("/list")
    public TableDataInfo<PtSysVideoVo> list(@Validated(QueryGroup.class) PtSysVideoBo bo, PageQuery pageQuery) {
        return iPtSysVideoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出视频列表
     */
    @ApiOperation("导出视频列表")
    @PreAuthorize("@ss.hasPermi('system:video:export')")
    @Log(title = "视频", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated PtSysVideoBo bo, HttpServletResponse response) {
        List<PtSysVideoVo> list = iPtSysVideoService.queryList(bo);
        ExcelUtil.exportExcel(list, "视频", PtSysVideoVo.class, response);
    }

    /**
     * 获取视频详细信息
     */
    @ApiOperation("获取视频详细信息")
    @PreAuthorize("@ss.hasPermi('system:video:query')")
    @GetMapping("/{id}")
    public AjaxResult<PtSysVideoVo> getInfo(@ApiParam("主键")
                                                  @NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iPtSysVideoService.queryById(id));
    }

    /**
     * 新增视频
     */
    @ApiOperation("新增视频")
    @PreAuthorize("@ss.hasPermi('system:video:add')")
    @Log(title = "视频", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody PtSysVideoBo bo) {
        return toAjax(iPtSysVideoService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改视频
     */
    @ApiOperation("修改视频")
    @PreAuthorize("@ss.hasPermi('system:video:edit')")
    @Log(title = "视频", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody PtSysVideoBo bo) {
        return toAjax(iPtSysVideoService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除视频
     */
    @ApiOperation("删除视频")
    @PreAuthorize("@ss.hasPermi('system:video:remove')")
    @Log(title = "视频" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@ApiParam("主键串")
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iPtSysVideoService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
